import Map from "ol/Map";
import LayerMgr from "./index";
import { MapPaths } from "../../config";
import TileLayer from "ol/layer/Tile";
import { XYZ } from "ol/source";

export default class BaseMap {
    private mapLayers: Array<any>;  // 用于存放现有全部图层
    private layerMgr: LayerMgr;
    private tileLayer: TileLayer;
    constructor(private map: Map) {
        this.layerMgr = new LayerMgr(this.map)
        this.mapLayers = MapPaths   // 初始化地图图层

    }

    /**
     * 切换底图图层
     * @param typeName T_Vector  天地图矢量图层，T_Image 天地图影像图层
     */
    public changeBaseMap(typeName: string) {
        this.mapLayers.forEach(item => {    
            if (item.key == typeName) {
                this.tileLayer = new TileLayer({
                    source: new XYZ({
                        url: item.url
                    }),
                    zIndex: 1
                })
                this.layerMgr.addLayer(this.tileLayer, typeName, false)
            } else {
                this.layerMgr.removeLayer(item.key)
            }
        })
    }

}
